import { h } from 'vue'
import {callConfirmMethod} from '@/common/layer-com-utils.js'
import viewDetailOrder from './viewDetailOrder.vue'

/**
 * 查看订单详细
 * @param {Array} serverDataList  - 当前表格的所有数据
 * @param {string} orderId  - 当前需要查看的订单Id
 */
function layerViewDetailOrder(serverDataList,orderId){
    let serverData = {};
    const orderList = serverDataList.filter(it=>it.order_id==orderId);
    for(let i=0;i<orderList.length;i++){
        const item = orderList[i]
        // 找到根订单Id
        if(item.order_child_id==''||/_1$/.test(item.order_child_id)){
            serverData = item
            serverData.product_list=[]
        }
        const { pack_id,fast_status,verify_code,order_child_id } = item
        serverData.product_list.push({
            pack_type:pack_id[0].text,
            fast_status,
            verify_code,
            order_child_id
        })

    }
    console.log(serverData)
    let confirmMethod=[];
    layer.open({
        title:`订单详细`,
        type:1,
        area:[`580px`,`500px`],
        content:h(viewDetailOrder,{
            serverData,
            callback:(arrayFn)=>confirmMethod=arrayFn
        }), 
        appContext:getApp().$vm.$.appContext,
        shade: true, 
        shadeClose:false,
        btn: [{
            text:`知晓并关闭`, 
            callback: (layerId) =>callConfirmMethod.call(this,confirmMethod[0],layerId)
        }]
    })
}

export default {
    layerViewDetailOrder
}